; -*-Scheme-*-

;************************************************************************/
;*                                                                      */
;* Copyright (c) 2003-2009 Vladimir Tsichevski <tsichevski@gmail.com>   */
;*                                                                      */
;* This file is part of bigloo-lib (http://bigloo-lib.sourceforge.net)  */
;*                                                                      */
;* This library is free software; you can redistribute it and/or        */
;* modify it under the terms of the GNU Lesser General Public           */
;* License as published by the Free Software Foundation; either         */
;* version 2 of the License, or (at your option) any later version.     */
;*                                                                      */
;* This library is distributed in the hope that it will be useful,      */
;* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    */
;* Lesser General Public License for more details.                      */
;*                                                                      */
;* You should have received a copy of the GNU Lesser General Public     */
;* License along with this library; if not, write to the Free Software  */
;* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 */
;* USA                                                                  */
;*                                                                      */
;************************************************************************/

(module
 entities
 (import xmlregexp xtree)
 (library common)
 (include "common.sch")
 (extern
  (include "libxml/tree.h")
  )
 )

;; void xmlInitializePredefinedEntities (void);

;; xmlEntityPtr
;;                      xmlNewEntity            (xmlDocPtr doc,
;;                                               const string name,
;;                                               int type,
;;                                               const string ExternalID,
;;                                               const string SystemID,
;;                                               const string content);
#|
(define (xml-add-doc-entity::xml-entity
         doc::xml-doc
         name::string
         type
         external-id
         system-id
         content::string)
  (let ((doc::xml-doc doc)
        (name::string name)
        (type::int (or type )
        (external-id::string
          (or external-id (pragma::string "NULL")))
        (system-id::string
          (or system-id (pragma::string "NULL")))
        (content::string content))
    (pragma::xml-entity
      "xmlAddDocEntity($1, (char*)$2, $3, (char*)$4, (char*)$5, (char*)$6)"
      doc
      name
      type
      external-id
      system-id
      content)))
|#

(define-export (xml-add-doc-entity::xml-entity
                doc::xml-doc
                name::string
                content
                #!key
                type
                external-id
                system-id
                )
  (let ((doc::xml-doc doc)
        (name::string name)
        (type::xml-entity-type (or type 'internal-general))
        (external-id::string
          (or external-id (pragma::string "NULL")))
        (system-id::string
          (or system-id (pragma::string "NULL")))
        (content::string (or content (pragma::string "NULL"))))
    (pragma::xml-entity
      "xmlAddDocEntity($1, (char*)$2, $3, (char*)$4, (char*)$5, (char*)$6)"
      doc
      name
      type
      external-id
      system-id
      content)))

(define-export (xml-add-dtd-entity::xml-entity
                doc::xml-doc
                name::string
                content::string
                #!key
                type
                external-id
                system-id
                )
  (let ((doc::xml-doc doc)
        (name::string name)
        (type::xml-entity-type (or type 'internal-general))
        (external-id::string
          (or external-id (pragma::string "NULL")))
        (system-id::string
          (or system-id (pragma::string "NULL")))
        (content::string content))
    (pragma::xml-entity
      "xmlAddDtdEntity($1, (char*)$2, $3, (char*)$4, (char*)$5, (char*)$6)"
      doc
      name
      type
      external-id
      system-id
      content)))

(define-func xmlGetPredefinedEntity xmlEntity ((string name "char*")))
;;(define-func xmlGetDocEntity xmlEntity ((xmlDoc doc)(string name "char*"))(false))

(define-export (xml-get-doc-entity
                doc::xml-doc
                name::string)
  (let* ((doc::xml-doc doc)
         (name::string name)
         (result::xml-entity (pragma::xml-entity "xmlGetDocEntity($1, (char*)$2)"
                                                 doc
                                                 name)))
    (and (pragma::bool "$1 != NULL" result)
         result)))

(define-export (xml-get-dtd-entity
                doc::xml-doc
                name::string)
  (let* ((doc::xml-doc doc)
         (name::string name)
         (result::xml-entity (pragma::xml-entity "xmlGetDtdEntity($1, (char*)$2)"
                                                 doc
                                                 name)))
    (and (pragma::bool "$1 != NULL" result)
         result)))


;; (define-func xmlGetDtdEntity xmlEntity ((xmlDoc doc)(string name "char*")))
(define-func xmlGetParameterEntity xmlEntity ((xmlDoc doc)(string name "char*")))
(define-func xmlEncodeEntitiesReentrant string ((xmlDoc doc)(string input "char*")))
(define-func xmlEncodeSpecialChars string ((xmlDoc doc)(string input "char*")))
;; (define-func xmlCreateEntitiesTable xmlEntitiesTable ())
;; (define-func xmlCopyEntitiesTable xmlEntitiesTable ((xmlEntitiesTable table)))
;; (define-func xmlFreeEntitiesTable void ((xmlEntitiesTable table)))
;; (define-func xmlDumpEntitiesTable void ((xmlBuffer buf)(xmlEntitiesTable table)))
(define-func xmlDumpEntityDecl void ((xmlBuffer buf)(xmlEntity ent)))

